package pl.edu.agh.neuraleconomy.ui.component;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;

import pl.edu.agh.neuraleconomy.core.ta.indicator.Indicator;

public class IndicatorsPanel extends Composite{

	private Map<Indicator, Button> checkBoxesMap = new HashMap<Indicator, Button>();
	
	public IndicatorsPanel(Composite parent, int style) {
		super(parent, style);
		init();
	}
	
	public EnumSet<Indicator> getSelectedIndicators(){
		EnumSet<Indicator> indicators = EnumSet.noneOf(Indicator.class);
		for(Indicator i : checkBoxesMap.keySet()){
			if(checkBoxesMap.get(i).getSelection()){
				indicators.add(i);
			}
		}
		return indicators;
	}
	
	private void init(){
		GridLayout layout = new GridLayout(1,false);
		setLayout(layout);
		
		Group group = new Group(this, SWT.SHADOW_IN);
		group.setLayout(layout);
		group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		group.setText("Indicators");
		
		EnumSet<Indicator> indicators = EnumSet.allOf(Indicator.class);
		for(Indicator i : indicators){
			addCheckBox(i,group);
		}
	}
	
	private void addCheckBox(Indicator i, Group group){
		Button button = new Button(group, SWT.CHECK);
		button.setText(i.getName());
		checkBoxesMap.put(i, button);
	}

}
